/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjut.se1603.wwm;

import edu.fjut.se1603.wwm.DAO.impl.PetDaoImpl;
import edu.fjut.se1603.wwm.entity.Pet;
import java.sql.Date;
import java.util.List;
import java.util.Scanner;
import edu.fjut.se1603.wwm.DAO.impl.AccountDaoImpl;
import edu.fjut.se1603.wwm.DAO.impl.PetDaoImpl;
import edu.fjut.se1603.wwm.DAO.impl.PetOwnerDaoImpl;
import edu.fjut.se1603.wwm.DAO.impl.PetStoreDaoImpl;
import edu.fjut.se1603.wwm.entity.Account;
import edu.fjut.se1603.wwm.entity.Pet;
import edu.fjut.se1603.wwm.entity.PetOwner;
import edu.fjut.se1603.wwm.service.impl.PetOwnerServiceImpl;
import edu.fjut.se1603.wwm.service.login;
import java.sql.Date;
import java.util.List;
import java.util.Scanner;
import sun.net.ftp.FtpDirEntry;

/**
 *
 * @author Daydream
 */
public class mainClass {

    public static void main(String[] args) {
        PetOwnerServiceImpl posi = new PetOwnerServiceImpl();
        PetOwner owner = new PetOwner();
        PetDaoImpl pet = new PetDaoImpl();
        PetOwnerDaoImpl podi = new PetOwnerDaoImpl();
        PetStoreDaoImpl psdi = new PetStoreDaoImpl();
        AccountDaoImpl adi = new AccountDaoImpl();

        login.display();
        System.out.println("请选择输入登录模式，输入1为宠物主人登录，输入2为宠物商店登录");
        Scanner sc = new Scanner(System.in);
        int sc1 = sc.nextInt();
        if (sc1 == 1) {
            owner = posi.login();
            System.out.println("登录成功，您可以购买和卖出宠物，购买宠物请输入1，卖出宠物请输入2");
            System.out.println("1：购买宠物");
            System.out.println("2：卖出宠物");
            int sc2 = sc.nextInt();
            if (sc2 == 1) {
                System.out.println("--------以下是库存宠物--------");
                List<Pet> pets = pet.getList();
                Pet[] buy_Pets = new Pet[100];
                int num = 0;
                for (int i = 0; i < pets.size(); i++) {
                    if (pets.get(i).getOwner_id() == 0) {
                        System.out.println("序号：" + (num + 1) + " 我的名字是：" + pets.get(i).getName() + " 我是：" + pets.get(i).getTypename() + " 要购买我要花：" + pets.get(i).getPrice());
                        buy_Pets[num] = pets.get(i);
                        num++;
                    }
                }
                System.out.println("--------请选择要购买哪个宠物，并输入选择项的序号--------");
                int a = (sc.nextInt() - 1);
                posi.buy(buy_Pets[a], owner);
            } else if (sc2 == 2) {
                System.out.println("--------我的宠物列表--------");
                List<Pet> pets = pet.getList();
                Pet[] buy_Pets = new Pet[100];
                int num = 0;
                for (int i = 0; i < pets.size(); i++) {
                    if (pets.get(i).getOwner_id() == owner.getId()) {
                        System.out.println("序号：" + (num + 1) + " 我的名字是：" + pets.get(i).getName() + " 我是：" + pets.get(i).getTypename() );
                        buy_Pets[num] = pets.get(i);
                        num++;
                    }
                }
                System.out.println("--------请选择要出售的宠物序号--------");
                int a = (sc.nextInt() - 1);
                posi.sell(buy_Pets[a], owner);
            }
            else{
                System.out.println("无效输入！");
            }
        }
    }

}
